package net.csdn.business.common.domain.issue;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

/**
 * issue 操作事件 code < 0 暂不作为change事件入库
 *
 * @author likun
 * @date 2022/11/16 16:39
 */
@Getter
@AllArgsConstructor
public enum IssueActionEventEnum {
    /**
     * 创建issue
     */
    CREATE("create", 0),
    COMMENT("comment", 1),
    UPDATE_STATUS("updateStatus", 2),
    ASSIGN_USER("assignUser", 3),
    PIN("pin", 4),
    LOCK("lock", 5),
    UPDATE_TITLE("update_title", 6),
    MOVE("move", 7),
    LABEL("label", 8),
    MILEPOST("milepost", 9),
    SET_PRIORITY("set_priority", 10),

    COMMENT_AT("commentAt", -1),
    ;
    private final String action;

    private final Integer code;

    public static IssueActionEventEnum ofCode(Integer code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (IssueActionEventEnum event : IssueActionEventEnum.values()) {
            if (event.code.equals(code)) {
                return event;
            }
        }
        throw new IllegalArgumentException("IssueActionEventEnum param error");
    }
}